package com.njupt.swg.threadstudyjimin.item06.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.njupt.swg.threadstudyjimin.annotation.ThreadSafe;

@ThreadSafe
public class ImmutableExample3 {
    private final static ImmutableList list = ImmutableList.of(1,2,3);//可以无限写下去

    private final static ImmutableSet set = ImmutableSet.copyOf(list);

    private final static ImmutableMap<Integer,Integer> map = ImmutableMap.of(1,2,3,4);

    private final static ImmutableMap<Integer,Integer> map2 = ImmutableMap.<Integer,Integer>builder()
                                                                .put(1,2).put(3,4).build();


    public static void main(String[] args) {
        list.add(4);//会被标识为不建议使用，强行使用，会抛出异常
        set.add(4);
        map.put(5,6);
        map2.put(5,6);
    }
}
